package com.xuecheng.content.api;

import com.xuecheng.base.exception.ValidationGroups;
import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.content.config.MultipartSupportConfig;
import com.xuecheng.content.model.dto.AddCourseDto;
import com.xuecheng.content.model.dto.CourseBaseInfoDto;
import com.xuecheng.content.model.dto.EditCourseDto;
import com.xuecheng.content.model.dto.QueryCourseParamsDto;
import com.xuecheng.content.model.po.CourseBase;
import com.xuecheng.content.service.CourseBaseInfoService;
import com.xuecheng.content.util.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

@Api(value = "课程管理相关的接口",tags = "课程管理相关的接口")
@RestController
public class CourseBaseInfoController {
    @Autowired
    CourseBaseInfoService courseBaseInfoService;
    @ApiOperation("课程查询相关接口")
    @PreAuthorize("hasAuthority('xc_teachmanager_course_list')")//验证有无查看权限
    @PostMapping("/course/list")
    public PageResult<CourseBase> list(PageParams pageParams, @RequestBody QueryCourseParamsDto queryCourseParamsDto) {
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        String companyId_ = user.getCompanyId();
        Long companyId=null;
        if (StringUtils.isNotEmpty(companyId_)){
             companyId = Long.parseLong(companyId_);
        }
        PageResult<CourseBase> courseBasePageResult = courseBaseInfoService.selectList(companyId,pageParams, queryCourseParamsDto);
        return courseBasePageResult;
    }

    @PostMapping("/course")
    public CourseBaseInfoDto createCourseBaseInfo(@RequestBody @Validated({ValidationGroups.Insert.class}) AddCourseDto addCourseDto){
        CourseBaseInfoDto courseBaseInfo = courseBaseInfoService.createCourseBaseInfo(1232141425L, addCourseDto);
        return courseBaseInfo;
    }
    @GetMapping("/course/{id}")
    public CourseBaseInfoDto getCourseBaseInfo(@PathVariable Long id){
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        String username = user.getUsername();
        CourseBaseInfoDto courseBaseInfoDto = courseBaseInfoService.queryCourseInfo(id);
        return courseBaseInfoDto;
    }
    @PutMapping("/course")
    public CourseBaseInfoDto updateCourseBaseInfo(@RequestBody EditCourseDto editCourseDto){
        return courseBaseInfoService.updateCourseInfo(1232141425L,editCourseDto);
    }
    @DeleteMapping("/course/{id}")
    public void deleteCourseBaseInfo(@PathVariable Long id){
        Long companyId=1232141425L;
         courseBaseInfoService.deleteCourseInfo(companyId,id);
    }

}
